<template>
    <div>
        <el-row :gutter="20" v-permission="['getStatistics1,GET']">
            <template v-if="panels.length === 0">
                <el-col :span="6" v-for="i in 4" :key="i">
                    <el-skeleton style="width: 100%," animated loading>
                        <template #template>
                            <el-card shadow="hover" class="card">
                                <template #header>
                                    <div class="cardHeader">
                                        <el-skeleton-item variant="text" style="width: 50%" />
                                        <el-skeleton-item variant="text" style="width: 10%" />
                                    </div>
                                </template>
                                <el-skeleton-item variant="h3" style="width: 80%" />
                                <el-divider></el-divider>
                                <div class="cardText2">
                                    <el-skeleton-item variant="text" style="width: 50%" />
                                    <el-skeleton-item variant="text" style="width: 10%" />
                                </div>
                            </el-card>
                        </template>
                    </el-skeleton>
                </el-col>
            </template>

            <el-col :span="6" :offset="0" v-for="(item, index) in panels" :key="index">
                <el-card shadow="hover" class="card">
                    <template #header>
                        <div class="cardHeader">
                            <span class="cardHeaderText">{{ item.title }}</span>
                            <el-tag :type="item.unitColor || 'info'" effect="plain">
                                {{ item.unit }}
                            </el-tag>
                        </div>
                    </template>
                    <span class="cardText">
                        <CountTo :value="item.value" />
                    </span>
                    <el-divider></el-divider>
                    <div class="cardText2">
                        <span>{{ item.subTitle }}</span>
                        <span>{{ item.subValue }}</span>
                    </div>
                </el-card>
            </el-col>
        </el-row>
        <IndexNavs />
        <el-row :gutter="20" class="IndexCard" v-permission="['getStatistics2,GET']">
            <el-col :span="12" :offset="0">
                <IndexChart v-permission="['getStatistics3,GET']"></IndexChart>
            </el-col>
            <el-col :span="12" :offset="0">
                <IndexCard tip="店铺及商品提示" title="店铺及商品提示" :btns="goods" class="IndexCardIndexCard"></IndexCard>
                <IndexCard tip="需要立即处理的交易订单" title="交易提示" :btns="order"></IndexCard>
            </el-col>
        </el-row>
    </div>
</template>
<script setup>
import { statistics1, statistics2 } from '@/api/index.js'
import { ref } from 'vue'
import CountTo from '@/pages/components/CountTo.vue';
import IndexNavs from '@/pages/components/IndexNavs.vue';
import IndexChart from '@/pages/components/IndexChart.vue';
import IndexCard from '@/pages/components/IndexCard.vue';

// 获取面板信息
const panels = ref([])
statistics1().then(res => {
    panels.value = res.panels
})

const goods = ref([])
const order = ref([])
statistics2().then(res => {
    goods.value = res.goods
    order.value = res.order
})
</script>
<style scoped lang="less">
.card {
    border: 0;

    .cardHeader {
        display: flex;
        justify-content: space-between;

        .cardHeaderText {
            font-size: 14px;
        }
    }

    .cardText {
        font-size: 1.5rem;
        font-weight: bold;
        color: #939393;
    }

    .cardText2 {
        display: flex;
        justify-content: space-between;
        font-size: 14px;
        color: #7c7c7c;
    }
}

.IndexCard {
    margin-top: 20px;

    .IndexCardIndexCard {
        margin-bottom: 30px;
    }
}
</style>